from IPy import IP
import os
import threading
def ping_ip(ipaddr):
    try:
        result = os.system("ping %s -c 1 -w 1 &> /dev/null" %(ipaddr))
        if result == 0:
            fp = open("user_ip.txt","a+")
            fp.write(f"{ipaddr}\n")
            fp.close()
        else:
            f = open("unuser_ip.txt","a+")
            f.write(f"{ipaddr}\n")
            f.close()
    except FileNotFoundError as e:
        print(e,"文件没有找到")
try:

    for i in range(0,256):
        t = threading.Thread(target=ping_ip,args=("192.168.8.%s" %i,))
        t.start()
except IndexError as e:
    print(e,"下标越界")

